<template>
	<view>
	<u-row customStyle="background: #eee; height: 80rpx;padding-left:30rpx;">
		<u-col >
			<u--text prefixIcon='/static/icon/shopN.png' size='15' iconStyle="margin-right:10rpx" v-if="shop.shop_name " :text="'当前店铺：'+shop.shop_name  "></u--text>
			<u--text prefixIcon='/static/icon/shopN.png' size='15' iconStyle="margin-right:10rpx" v-else text="当前店铺： 未选择店铺 "></u--text>
		</u-col>
	</u-row>
	<view style="padding: 0 32rpx;"> 
	
	<u-row customStyle="margin-top:16rpx">
		<u-col span="2"    >
			<u--text text="名称"></u--text>
		</u-col>
		<u-col span="4">
	
			<u--text text="过期时间"></u--text>
		</u-col>
		<u-col span="3">
			<u--text text="所属店铺"></u--text>
		</u-col>
		<u-col span="3">
			 
		</u-col>
	</u-row>
	<u-empty 
		iconSize='120'
		textSize='18'
		marginTop='150'
		mode="data"
		v-if="goodsList.length <=0"
	>
	</u-empty>
	<u-list-item v-else v-for="(item, index) in goodsList" :key="index"  >
		<u-row customStyle="margin-top: 16rpx;">
			<u-col span="2"  >
				<u--text :text="item.goods_name"></u--text>
			</u-col>
	
			<u-col span="4">
				<u-text v-if="!item.expiration_date"  text=" 暂无 "></u-text>
				<u-text v-else mode="date" :text="Number(item.expiration_date)"></u-text>
			</u-col>
			<u-col span="3">
				 
			</u-col>
			<u-col span="2">
				 <u-button type="primary" :text="item.temporary==1?'取消':'选择'" @click="temporary(item,index)" size="small"></u-button>
			</u-col>
		</u-row>
		<u-line customStyle="margin:16rpx 0"></u-line>
	</u-list-item>
		<u--text color='#7a7a7a' text='提醒' customStyle='padding-top: 32rpx;'></u--text>
		<u--text color='#7a7a7a' text='1.向左侧滑动,可删除或修改配置,只有店主才有移除权限'></u--text>
		<u--text color='#7a7a7a' text='2.规则调整后,新录入商品立即生效'></u--text>
		<u--text color='#7a7a7a' text='3.若需要调整历史商品临期日期.点击【校准商品】'></u--text>
		<view class="" style="position: fixed;bottom: 20rpx;width: 700rpx;">
			<u-row>
				<u-col span="2.5">
					<!-- <u-button type="primary" text="校准商品"></u-button> -->
				</u-col>
				<u-col span="7"  >
					<u-button type="success" text="新增配置" @click="addSetting"></u-button>
				</u-col>
			</u-row>
		</view>
		
		<u-modal :show="modalShow"  title='提示'
				cancelText='返回' 
				@cancel='cancel' 
				:showCancelButton='true' 
				confirmText='去解锁'  
				:content='mContent'
				@close='cancel'
				@confirm="confirm" ref="uModal" 
				:asyncClose="true"></u-modal>
	</view>
	</view>
</template>

<script>
	var that
	var ERGoodsScan = require('../../../service/ERGoodsScan.js'), mERGoodsScan;
	 
	export default {
		 
		data() {
			return {
				goodsList:[],
				mContent:'临期配置仅对会员开发，升级会员后即可解锁此功能！',
				modalShow: false,
				shop:{},
				shopName:''
			}
		},
		onLoad() {
			that = this
			mERGoodsScan = new ERGoodsScan(this.mNetTool)
		},
		mounted() {
			let userInfo = uni.getStorageSync('userInfo')
			// let viewShopListItem = uni.getStorageSync('viewShopListItem')
		 
			// if(viewShopListItem){
			// 	that.shop  = viewShopListItem
			// 	mERGoodsScan.list({
			// 		temporary:1,
			// 		own_store_id:viewShopListItem.id
			// 	},res => {
			// 		console.log(res)
			// 		that.goodsList = res.rows
			// 	}) 
			// }else{
			// 	uni.$u.toast('当前未选择店铺！')
			// }
			
			// if(!userInfo){
			// 	uni.showModal({
			// 		content:'请登录后使用',
			// 		success(r) {
			// 			if(r.confirm){
			// 				uni.navigateTo({
			// 					url:'../login/login'
			// 				})
			// 			}else {
			// 				uni.navigateBack({
								
			// 				})
			// 			}
			// 		}
			// 	})
			// }
			if(userInfo){
				// let overTime = new Date(userInfo.vip_end_time).getTime()
				// let nowTime = new Date().getTime()
				 
				// if(overTime > nowTime){
				// 	that.isVip = true
				// 	let addInfo = {
				// 		created_by:userInfo.id, 
				// 	}
				// 	// uni.showToast({
				// 	// 	title:'请稍等',
				// 	// 	icon:'loading',
				// 	// 	duration:3000
				// 	// })
				// 	// mERgoodsShelf.list(addInfo,res => {
				// 	// 	console.log(res)
				// 	// 	that.shelfList = res.rows
				// 	// 	uni.hideToast()
				// 	// })
				// }else if(overTime < nowTime){
				// 	that.mContent = '您的会员已过期，邀请店员仅对会员开发，升级会员后即可解锁此功能'
				// 	that.modalShow = true
				// }else {
				// 	that.modalShow = true
				// }
			}
			 
		},
		onShow() {
			let userInfo = uni.getStorageSync('userInfo')
			if(!userInfo){
				uni.showModal({
					content:'请登录后使用',
					success(r) {
						if(r.confirm){
							if (that.autoStatus) { //支持一键登录
								console.log('进入一键登录')
								that.keyLogin()
							} else {
								uni.navigateTo({
									url: '../login/login'
								})
							}
						}else {
							uni.navigateBack({
								
							})
						}
					}
				})
			}else {
				that.getGoods()
			}
		},
		methods: {
			getGoods(){
				let viewShopListItem = uni.getStorageSync('viewShopListItem')
						 
				if(viewShopListItem){
					that.shopName = viewShopListItem.shop_name
					uni.showLoading({
						title:'请稍等'
					})
					that.shop  = viewShopListItem
					mERGoodsScan.list({
						temporary:1,
						own_store_id:viewShopListItem.id
					},res => {
						console.log(res)
						uni.hideLoading()
						that.goodsList = res.rows
					}) 
				}else{
					uni.$u.toast('当前未选择店铺！')
				}
			},
			temporary(item,index){
				let userInfo = uni.getStorageSync('userInfo')
				if(!userInfo){
					uni.$u.toast('登录信息失效，请重新登录')
					uni.switchTab({
						url:'../userCenter/userCenter'
					})
				}
				console.log(item)
				if(item.temporary === 1){
					uni.showLoading({
						title:'请稍等'
					})
					mERGoodsScan.update({
						id:item.id,
						temporary:0,
						change_person:userInfo.nick_name,
						updated_by:userInfo.id,
					},res => {
						 
						uni.hideLoading()
						uni.$u.toast('修改成功')
						that.goodsList[index].temporary = 0
					})
				}else{
					mERGoodsScan.update({
						id:item.id,
						temporary:1,
						change_person:that.userInfo.nick_name,
						updated_by:that.userInfo.id,
					},res => {
						uni.hideLoading()
						uni.$u.toast('修改成功')
						that.goodsList[index].temporary = 1
					})
				}
			}, 
			addSetting(){
				uni.navigateTo({
					url:'newDateSetting/newDateSetting?shopId='+that.shop.id
				})
			},
			cancel(){
				this.modalShow = false
				uni.navigateBack({
					delta:0
				})
			},
		}
	}
</script>

<style>

</style>
